Reading Assignment 2
OpenMP
Write your answers in a PDF and upload the document on Gradescope for submission. The due date is given on Gradescope. Each question is worth 10 points.
Starter code for all the questions.
Please watch the videos 06 through 12 and the slides before answering the questions:
- C++ threads; Slides; Code
- Introduction to OpenMP; Slides; Code
- 06 C++ threads; Video
- 07 Promise and future; Video
- 08 mutex; Video
- 09 Introduction to OpenMP; Video
- 10 OpenMP Hello World; Video
- 11 OpenMP for loop; Video
- 12 OpenMP clause; Video
Answer these questions:
- In
cpp_thread.cpp
, complete the exercise with functionf4
. Your code should pass theassert
. Turn in your code. - In
cpp_thread.cpp
, complete the exercise witht6
andmax_result
. Your code should pass theassert
. Turn in your code. - In
mutex_demo.cpp
, explain what would happen if you remove line 45:g_mutex.unlock();
- In
hello_world_openmp.cpp
, explain what the line 60 does:#pragma omp parallel num_threads(nthreads)
. Explain thenum_threads
clause. - Using an OpenMP pragma, modify the file
matrix_prod_openmp.cpp
such that the execution of the code between line 90 and 99 is accelerated by using multiple threads. Report on your running times as you vary the number of threads. Use the options-p
and-n
. Turn in your code. - In shared_private_openmp.cpp, explain what would happen if you remove
private(is_private)
on line 31.